// pagesCollect/pages/collect/edit/components/imglist/imglist.js
import { baseUrl,chooseImageTap } from "../../../../../../api/request"

Component({
  properties: {
    imgStr: {
      type: String,
      value: '',
    },
  },
  lifetimes: {
    attached() {},
    detached() { }
  },
  attached() {},
  data: {
    baseUrl:baseUrl,
    imglist:[],
  },
  observers: {
    'imgStr': function (value) {
        this.setData({
          imglist:value?value.split(','):[]
        })
    }
  },
  methods: {
    openImgChk(){
      chooseImageTap((res)=>{
        let {imglist} = this.data;
        imglist.push(res.fileName[0])
        this.setData({imglist})
        this.triggerEvent('imgStrChg',imglist.join(','))
      })
    },
    del(e){
      let index = e.currentTarget.dataset.index;
      let {imglist} = this.data;
      imglist.splice(index,1)
      this.setData({imglist})
      this.triggerEvent('imgStrChg',imglist.join(','))
    }
  }
})